/******************************************************************************

 ******************************************************************************
  File Name	:medium_manage.h
  Version		:001
  Author		:liangH
  Description	:define medium manage class
  History		:20120530 new
  Modification	: 

******************************************************************************/

#ifndef __MEDIUM_MANAGE_H__
#define __MEDIUM_MANAGE_H__

#include "config.h"

class Medium_manage
{
	private:
		unsigned char sd_exist;/*0 shows that sd card dose not exist, 1 shows that sd card exists*/
		unsigned char sd_status;/*status of sd, 0 shows write unable, 1 shows write able, 2 shows disk full*/
		unsigned char sd_operate_status;/*operate status of sd card, for example: reading, writing, deleting, formatting*/
		unsigned long sd_total_capacity;/*total capacity of ad card*/
		unsigned long sd_available_capacity;/*available capacity of ad card*/
		/*folder path that is traversed*/
		pthread_mutex_t medium_manage_lock;/*lock*/
		pthread_mutex_t read_write_lock;/*read and write lock*/
		pthread_t delete_file_thread;/*the thread of deleting file*/
		pthread_t force_delete_file_thread;/*the thread of deleting file forcibly*/
		pthread_t sd_card_maintain_thread;/*the thread of maintaining sd card*/
		pthread_t sd_card_check_thread;/*the pthread of checking sd card if exists*/
		HI_BOOL delete_pthread_flag;/*the flag of delete expired pthread, that shows if delete_file_thread has been created*/
		HI_BOOL force_delete_pthread_flag;/*the flag of delete expired pthread forcibly, that shows if delete_file_thread_force has been created*/
		HI_BOOL maintain_pthread_flag;/*the flag of maintain sd card pthread, that shows if sd_card_maintain_thread has been created*/
		HI_BOOL sd_card_check_flag;/*the flag of sd card check pthread*/
	/*constructed function and deconstructed function*/
	public:
		Medium_manage();/*constructed function*/
		~Medium_manage();/*deconstructed function*/

	/*set,get member functin*/
	public:
		void set_sd_exist( unsigned char temp_sd_exist);
		unsigned char get_sd_exist();
		void set_sd_status(unsigned char temp_sd_status);
		unsigned char get_sd_status();
		void set_sd_operate_status(unsigned char temp_sd_operate_status);
		unsigned char get_sd_operate_status();
		void set_sd_total_capacity(unsigned long temp_sd_total_capacity);
		unsigned long get_sd_total_capacity();
		void set_sd_available_capacity(unsigned long temp_sd_available_capacity);
		unsigned long get_sd_available_capacity();
		void set_delete_pthread_flag(HI_BOOL temp_pthread_flag);
		HI_BOOL get_delete_pthread_flag();
		void set_force_delete_pthread_flag(HI_BOOL temp_pthread_flag);
		HI_BOOL get_force_delete_pthread_flag();
		void set_maintain_pthread_flag(HI_BOOL temp_maintain_pthread_flag);
		HI_BOOL get_maintain_pthread_flag();
		void set_sd_card_check_flag(HI_BOOL temp_sd_card_check_flag);
		HI_BOOL get_sd_card_check_flag();
		void set_sd_card_maintain_thread(unsigned long thread_ID);
	/*set,get member functin end*/

	/*basic function*/
		char get_space(unsigned char device_type);
		long get_total_space(char *device_path);
		long get_free_space(char *device_path);
		unsigned char create_dir(char *dirname);
		unsigned char create_delete_file_thread();
		unsigned char create_force_delete_file_thread();
		unsigned char create_sd_card_maintain_thread(unsigned char maintain_flag);
		unsigned char create_sd_card_check_thread();
		unsigned char stop_sd_card_check_thread();
		int get_dirlist(char *diskpath, struct dirent ***namelist);
		int get_sub_dirlist(char *diskpath, struct dirent ***namelist);
		int get_filelist(char *diskpath, struct dirent ***namelist);
		unsigned char delete_file(char *path);
		unsigned char delete_folder(char *path);
		void getfilesize(char *filename, unsigned long *filesize, int *modify_time);
		void getfilesize(char *filename, unsigned short *filesize, int *modify_time);
		void change_filename(char *srcfilename, char *dst_name);
		unsigned char copy_file(char *srcfilename, char *dst_name);
		char mount_device(char *mount_src, char flag);
		char unmount_device(char flag);
		char install_driver(char flag);
		int judge_file_exist(char *filename);/*check if file exists*/
		char format_sd();
		int sd_fix();
		char check_fs_read_only();
		char auto_mount(char sourec_flag);/*auto mount device, sd card or hdd card*/
	/*basic function end*/

	private:	
	/*inside process function*/
		int test_sd_exist();
		int FWRITE(FILE *fp, const char *buf, int nbytes);
		int FSEEK(FILE *fp, int off_set);
		void HexDisplay(const unsigned char *Data, int Length);
		int FREAD(FILE *fp, char *buf, int nbytes);
		void FERROR(FILE *fp);
		FILE *FOPEN(const char *path, const char *mode);
	/*inside process function end*/
};

#endif

